﻿#ifndef SERVERMONITOR_H
#define SERVERMONITOR_H

#include <QObject>
#include <QWebSocket>
#include <QJsonDocument>
#include <QJsonObject>
#include <QTimer>
#include <QMutex>
#include <QWaitCondition>
#include <QImage>

extern QMutex g_DebugMutex;
extern QWaitCondition g_DebugCondition;

class ServerMonitor : public QObject
{
    Q_OBJECT
public:
    ServerMonitor( QObject *parent = nullptr);

private:
    QWebSocket *pWebsocket {nullptr};
    QTimer *conTimer {nullptr};

    QString wsurl {"ws://127.0.0.1:12345"};
    bool isServerConnected {false}; // 是否与服务器连接成功
signals:
    void sig_ServerCommandReady(QJsonObject);        //    服务器命令解析完成，可以读取
public slots:
    void slot_init();
    void slot_timerout();
    void slot_wsconnected();
    void slot_wsdisconnected();
    void slot_binaryMessageReceived(const QByteArray &);
    void slot_textMessageReceived(const QString &message);
    void slot_error(QAbstractSocket::SocketError);
    void slot_sendDataToServer(QJsonObject data);    //向上位机服务端发送数据
    void slot_imgResultToServer(QImage);
};

#endif // ServerMonitor_H
